import request from "@/utils/request";
import { RoleItemType, RoleMenuListType, RoleResponseType } from "./types";

/**
 * 获取角色分页列表
 * @param page
 * @param limit
 * @param data
 * @returns
 */
export const reqGetRoleList = (
  page: number,
  limit: number,
  roleName: string
) => {
  return request.get<null, RoleResponseType>(
    `/admin/acl/role/${page}/${limit}?roleName=${roleName}`
  );
};

/**
 * 请求添加角色
 * @param role 角色信息
 * @returns
 */
export const reqAddRoleInfo = (role: RoleItemType) => {
  return request.post(`/admin/acl/role/save`, role);
};

/**
 * 请求修改角色
 * @param role 角色信息
 * @returns
 */
export const reqUpdateRoleInfo = (role: RoleItemType) => {
  return request.put(`/admin/acl/role/update`, role);
};

/**
 * 请求删除角色
 * @param id 角色id
 * @returns
 */
export const reqDelRoleInfo = (id: number) => {
  return request.put(`/admin/acl/role/remove/${id}`);
};

/**
 * 请求根据角色Id获取菜单
 * @param roleId
 * @returns
 */
export const reqGetMenu = (roleId: number) => {
  return request.get<null, RoleMenuListType>(
    `/admin/acl/permission/toAssign/${roleId}`
  );
};

/**
 * 请求给角色添加权限
 * @param roleId 
 * @param permissionId 
 * @returns 
 */
export const reqRoleAddMenu = (roleId: number, permissionId: number[]) => {
  return request.post(
    `/admin/acl/permission/doAssign?roleId=${roleId}&permissionId=${permissionId}`
  );
};
